function rt_driver_dev(T_interval, switches, siteIDs, av_win, av_thresh)
    % Script to drive rt suite
    %
    % (Typical) Usage:
    %
    % >> rt_driver()
    %
    % results in the following default values being used:
    %
    % T_interval = [(now - 14 days) now], where times are "serial date numbers" 
    %              (see MATLAB help for more information on sdn's)
    %              To specify a different interval, provide it as a string* in 
    %              the format [<sdn(start)> <sdn(stop)>] where <sdn(start)>
    %              (resp. stop) is the beginning (resp. end) of the time interval 
    %              as a serial date number.
    %
    % switches   = containers.Map({'ascii', 'plot', 'ftp', 'close_plot', 'exit'}, [1 1 1 1 1]),
    %              where:
    %              the value associated with 'ascii' controls whether text output is generated, 
    %              'plot' controls whether graphic output is generated, 
    %              'ftp' controls the uploading of the results, and 
    %              'close_plot' controls whether the plots are closed (1) or left open (0) after
    %                  being rendered on the screen.
    %              'exit' determines whether MATLAB is exited at completion
    %              The default value of 1 for all of these produces all output, uploads it all,
    %              destroys the plots after being rendered and saved, and closes MATLAB at the end.
    %              To switch any of these to zero, include in a string argument its identifier, 
    %              a space, and then the digit 0, followed by a semi-colon to separate multiple
    %              pairs.  For example, to turn "off" everything but plot generation, include as 
    %              the second argument the string*:
    %              [' or "]ascii 0; ftp 0; close_plot 0; exit 0[', resp. "] 
    %              (See MATLAB help for more information on MATLAB Map container objects.)
    %              
    % siteIDs    = {'MCH01BR', 'MCH01SR', 'MUK01BR', 'SQX01CF', 'SQX01SF', 'WPA13CR'}, where:
    %              'MCH01BR' & 'MCH01SR' => Manchester Station, bottom and surface, resp.,
    %              'MUK01BR' => Mukilteo Station, 
    %              'SQX01CF' & 'SQX01SF' => Squaxin Island Station, bottom and surface, resp.,
    %              'WPA13CR' => Wilapa Station.
    %              To specify a smaller subset of these, simply list them, space-separated, in a 
    %              single string*, e.g., [' or "]MUK01BR SQX01CF SQX01SF[', resp. "] will limit 
    %              processing to just the Mukilteo and both Squaxin stations.
    % av_win     = the averaging window, in days; default: 1
    %
    % av_thresh  = the averaging threshold, in number of consecutive samples; default: 70
    %
    % * To provide an argument as a string: from the MATLAB command prompt, use single quotes, 
    %   i.e., 'string', but from a Windows (DOS) command prompt, use double quotes, i.e., "string"
    
    import System.*
    import System.DateTime.*
    import containers.*
    global homeDir mail_recip mail_sender outgoingMailServ 
    global t_interval siteID doDO MS2MATLAB_DTOFFSET tag
    global sitedata
    doDO = true;
    ftp_closed = true;
    ftp_failure = false;
    MS2MATLAB_DTOFFSET = 693960; % Difference between MATLAB's and Microsoft's sdn's; 
                                 % necessary because the database server is a Microsoft product.
    
    try
        load rt_config; % includes homeDir, mail_recip, mail_sender, and outgoingMailServ 
    catch LE
        h = errordlg('Error trying to load configuration settings',...
             'Start-up Error');
        return;
    end
    if ~strcmp(homeDir, pwd)
        cd(homeDir);
    end
    setpref('Internet', 'SMTP_Server', outgoingMailServ);
    setpref('Internet', 'E_mail', mail_sender);

    % Set defaults, as necessary
    if nargin < 1 || isempty(T_interval)
        present = DateTime.UtcNow.ToOADate + MS2MATLAB_DTOFFSET;
        twoweeksago = present - 14;
        t_interval = [twoweeksago, present];
    else
        tmp = strtok(strtok(T_interval, ']'), '[');
        [start, stop] = strtok(tmp, ' ');
        t_interval = [str2double(start) str2double(stop)];
    end
    
    if nargin < 2 || isempty(switches)
        switches = Map({'ascii', 'plot', 'ftp', 'close_plot', 'exit'}, [1 1 1 1 1]);
    else
        tmp = Map({'ascii', 'plot', 'ftp', 'close_plot', 'exit'}, [1 1 1 1 1]);
        [start, stop] = strtok(switches, ';');
        while ~isempty(stop)
            [key, value] = strtok(start, ' ');
            tmp(key) = tmp(key) && str2double(value);
            [start, stop] = strtok(stop, ';');
        end
        switches = tmp;
    end

    if nargin < 3 || isempty(siteIDs)
        siteIDs = {'MCH01BR', 'MUK01BR', 'SQX01CF', 'SQX01SF', 'WPA13CR', 'MCH01SR'};
    else
        [start, stop] = strtok(siteIDs, ' ');
        siteIDs = {start};
        while ~isempty(stop)
            [start, stop] = strtok(strtrim(stop), ' ');
            siteIDs = union(siteIDs, strtrim(start));
        end        
    end
    
    if nargin < 4
        av_win = 1;
    end
    
    if nargin < 5
        av_thresh = 70;
    end
    
    % For each site
    for i=1:length(siteIDs)
        siteID = siteIDs{i};
        % Get to or create the right directory and confirm
        switch siteID(1:3)
            case 'MCH'
                localpath = 'Output\Manchester';
                path = '/eap/Mooring_Raw/Puget_Sound/Manchester/';
                if strcmp(siteID, 'MCH01SR') doDO=false; end
            case 'MUK'
                localpath = 'Output\Mukilteo';
                path = '/eap/Mooring_Raw/Puget_Sound/Mukilteo/';
            case 'SQX'
                localpath = 'Output\Squaxin';
                path = '/eap/Mooring_Raw/Puget_Sound/Squaxin/';
                if strcmp(siteID, 'SQX01SF') doDO=false; end
            case 'WPA'
                localpath = 'Output\Willapa';
                path = '/eap/Mooring_Raw/Willapa_Bay/Bay_Center_WPA13/';
                doDO=false;
            otherwise
                h = errordlg('Error in rt_driver.m, first switch block: ',...
                             'siteID not recognized!');
        end    
        cdworked = 1;
        if isdir(strcat('.\', localpath))
            cd(strcat('.\', localpath));
        elseif isdir(strcat('..\..\', localpath))
            cd(strcat('..\..\', localpath));
        else
            mdsuccessful = mkdir(strcat('\', localpath));
            if mdsuccessful
                cd(strcat('\', localpath));
            else
                cdworked = 0;
            end
        end
        if cdworked
            wd = pwd;
        end
        fnameroot = [siteID, '_REALTIME'];
        if t_interval(1) == t_interval(2)-14
            datednameroot = [siteID datestr(t_interval(2), '_ddmmmyyyy')];
        else
            datednameroot = [siteID datestr(t_interval(1), '_ddmmmyyyy_HHMMSS')...
                             'to' datestr(t_interval(2), 'ddmmmyyyy_HHMMSS')];
        end
        
        if i ~= length(siteIDs)
            tag = ['Continuing with ' siteIDs{i+1}];
        else
            tag = [siteID ' was the last site, ending'];
        end
        
        % Get the data
        data = rt_data_getter_dev();
        if isempty(data)% && ~strcmp(siteID, 'MCH01BR')
            continue
%         elseif strcmp(siteID, 'MCH01BR')
%             % While Manchester is down, make all dependent variables NaNs
%             t = t_interval(1):0.25:t_interval(2);
%             [P, T, C, S, D, DOS, DO] = deal(zeros(length(t),1) + NaN);
        else
            % Unpack
            t = datenum(data{1});
            [P, T, C, S, D, DOS, DO] = deal(data{2:end});
        end
                
        % Censor data for presentation
        switch siteID
            case 'MCH01BR' 
                remove = (P < 6.0);
            case 'MUK01BR' 
                remove = (P < 9.0);
            case 'SQX01BR'
                remove = (P < 3.0);
            case 'SQX01CF'
                remove = (P < 3.0);
            case 'WPA13CR' 
                remove = (P < 2.0);
            otherwise 
                remove = [];
        end
        P(remove) = NaN;
        T(remove) = NaN;
        if ~isempty(remove)
            remover = fix(remove);
            remover(remove) = NaN;
            D = D + remover;
            S = S + remover;
            C = C + remover;
        end
        DOS(remove) = NaN;
        if doDO
            DO(remove) = NaN;
        end
        T((T < 5 ) | (T > 20)) = NaN;
        if strcmp(siteID, 'WPA13CR')
            remove = (S < 10) | (S > 35);
        else
            remove = (S < 20) | (S > 35);
        end
        remover = fix(remove);
        remover(remove) = NaN;
        S = S + remover;
        D = D + remover;
        if doDO
            DO(DO < 3.0) = NaN;
        end
        
        % Produce the ascii output
        if switches('ascii')
            fname = rt_writedat_dev(fnameroot, t, P, T, C, S, D, DOS, DO);
            dlist = dir; 
            try
                if ismember(fname,{dlist.name}) % If successful, copy the file to the archive
                    [success, msg] = copyfile(fname, ['.\Archive\' datednameroot '.txt']);
                    if ~success
                        throw;
                    end
                else % Otherwise, report problem 
                    subj = 'RT error opening ascii output file ';
                    msg = fname;
                    throw;
                end
            catch ME
                sendmail(mail_recip, subj, msg);
            end
        end
        
        % Produce the plots
        if switches('plot')
            if ftp_closed
                server = 'www.ecy.wa.gov';
                try
                    ftpobj = ftp(server, 'eapuser', 'E@rth1!');
                    ftp_closed = false;
                    cd(ftpobj, '/eap/Mooring_Raw/');
                    capfile = mget(ftpobj, 'WebCaption.txt');
                catch FE
                    % If communicating w/ the ftp server fails, notify and use the Y: drive
                    if ~ftp_failure
                        sendmail(mail_recip, 'RT Error Notification',...
                                 ['Error opening the ftp server trying to get caption.'...
                                  'Using caption available on the Y: drive']);
                        ftp_failure = true;
                    end
                    capfile = {[wd '\WebCaption.txt']};
                end
            end
            f = fopen(capfile{1});
            caption = fgetl(f);
            fclose(f);
            reqtext = Map({'Title', 'Caption'}, {sitedata(1:4), caption});
            fh = rt_plotdat_dev(t_interval, t, P, T, S, DO, reqtext, av_win, av_thresh);
            if ishandle(fh)
                fname = [fnameroot '.png'];
                set(fh, 'InvertHardCopy', 'off');
                print(fh, '-dpng', '-r150', fname);
                hgsave(fh, ['.\Archive\' datednameroot])
                if switches('close_plot')
                    close;
                end
            else % rt_plotdat_dev caught and returned some kind of error
                sendmail(mail_recip, 'RT error in plotdat', getReport(fh, 'extended'));
            end
        end
        
        % Post the results
        if switches('ftp')
            % Try to open ftp connection, upload file, and close connection
            if ftp_closed
                server = 'www.ecy.wa.gov';
                try
                    ftpobj = ftp(server, 'eapuser', 'E@rth1!');
                catch FE
                    if ~ftp_failure
                        sendmail(mail_recip, 'RT Error Notification',...
                                 'Error opening ftp server trying to upload results.');
                        ftp_failure = true;
                    end
                end
                ftp_closed = false;
            end
            if ~ftp_failure
                cd(ftpobj, path);
                mput(ftpobj, [fnameroot '*']);
            end
        end
        
        % If the earlier directory walking worked, change back to the "home" directory
        if cdworked
            cd('..\..');
        end
        clear *equipID* statID equipNom* UTCdeploy auxChan calibType resCol sID *calib* ...
              serialNoDesc equipTypeID manufacturer modelDesc form* storedProc unitsDesc;
    end
    if ~ftp_closed && ~ftp_failure
        close(ftpobj)
    end
    if switches('exit')
        exit force
    end
end